package com.hjy.product.web;

import com.hjy.common.utils.R;
import com.hjy.product.service.SkuInfoService;
import com.hjy.product.vo.item.SkuItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ItemController {

    @Autowired
    private SkuInfoService skuInfoService;

    /**
     * 跳转到详情页面, 同时查出其对应的详情信息
     * @param skuId
     * @return
     */
    @RequestMapping("/{skuId}.html")
    public String index(@PathVariable("skuId") Long skuId) {
        return "item";
    }

    @RequestMapping("/{skuId}/info")
    @ResponseBody
    public R itemInfo(@PathVariable("skuId") Long skuId) {
        SkuItemVo skuItemVo = skuInfoService.item(skuId);
        return R.ok().put("data",skuItemVo);
    }
}
